/*
 * Copyright 2008-2010 GP Software
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 * MockFixedWidthUsersFileGenerator.java | Created on Sep 15, 2010
 */
package org.gp.fileGenerator.mock;

import org.gp.fileGenerator.model.User;
import org.gp.fileGenerator.model.UserWrapper;

import java.io.File;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

/**
 * Dummy fixed width file generator for User data model
 *
 * @author Paul Augustine C. Mendoza
 */
public class MockFixedWidthUsersFileGenerator extends AbstractMockUsersFileGenerator<List<UserWrapper>> {

    private static final String TEMPLATE = "users-fixedWidth.ftl";
    private static final String DEFINITION_FILE = "users-format.properties";

    public MockFixedWidthUsersFileGenerator(String templateBasePath) {
        super(templateBasePath, TEMPLATE);
    }

    @Override
    public List<UserWrapper> getDataModel() {
        List<UserWrapper> wrappedUsers = new ArrayList<UserWrapper>();
        URL url = this.getClass().getClassLoader()
                .getResource(DEFINITION_FILE);
        File definitionFile = new File(url.getPath());
        for (User user : getUsers()) {
            wrappedUsers.add(new UserWrapper(user, definitionFile));
        }
        return wrappedUsers;
    }

}
